home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / EmulationSpecial.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  6KB  |  441 lines

  1. /*
  2. **    EmulationSpecial.c
  3. **
  4. **    Special terminal emulation character handling
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* DoxON_xOFF():
  17.      *
  18.      *    This routine handles both xON and xOFF, it makes the emulation
  19.      *    swallow the character rather than printing it.
  20.      */
  21.  
  22. BOOL
  23. DoxON_xOFF()
  24. {
  25.     return(FALSE);
  26. }
  27.  
  28.     /* DoBackspace():
  29.      *
  30.      *    Special function: perform backspace.
  31.      */
  32.  
  33. BOOL
  34. DoBackspace()
  35. {
  36.     if(CursorX)
  37.     {
  38.         LONG DeltaX,MinX;
  39.  
  40.         CursorX--;
  41.  
  42.             /* What backspace mode are we in? */
  43.  
  44.         switch(Config->EmulationConfig->DestructiveBackspace)
  45.         {
  46.                 /* Do nothing */
  47.  
  48.             case 0:
  49.  
  50.                 RepositionCursor();
  51.                 break;
  52.  
  53.                 /* Shift the line to the left */
  54.  
  55.             case 2:
  56.  
  57.                 BackupRender();
  58.  
  59.                 RasterEraseCharacters(1);
  60.  
  61.                 if(FontScalingRequired)
  62.                 {
  63.                     if(CurrentCharWidth == SCALE_NORMAL)
  64.                     {
  65.                         DeltaX    = TextFontWidth * 2;
  66.                         MinX    = MUL_X(CursorX) * 2;
  67.                     }
  68.                     else
  69.                     {
  70.                         DeltaX    = TextFontWidth / 2;
  71.                         MinX    = MUL_X(CursorX) / 2;
  72.                     }
  73.                 }
  74.                 else
  75.                 {
  76.                     DeltaX    = TextFontWidth;
  77.                     MinX    = MUL_X(CursorX);
  78.                 }
  79.  
  80.                 ScrollLineEraseCharacters(1);
  81.  
  82.                 ScrollLineRaster(RPort,DeltaX,0,MinX,MUL_Y(CursorY),LastPixel,MUL_Y(CursorY + 1) - 1,FALSE);
  83.  
  84.                 BackupRender();
  85.  
  86.                 RepositionCursor();
  87.  
  88.                 break;
  89.  
  90.                 /* Clear the character below the cursor */
  91.  
  92.             default:
  93.  
  94.                 RepositionCursor();
  95.  
  96.                 ObtainSemaphore(&RasterSemaphore);
  97.  
  98.                 Raster[CursorY * RasterWidth + CursorX] = ' ';
  99.  
  100.                 ReleaseSemaphore(&RasterSemaphore);
  101.  
  102.                 BackupRender();
  103.  
  104.                 if(FontScalingRequired)
  105.                     PrintScaled(" ",1,CurrentFontScale);
  106.                 else
  107.                     Text(RPort," ",1);
  108.  
  109.                 BackupRender();
  110.  
  111.                 break;
  112.         }
  113.     }
  114.  
  115.     return(FALSE);
  116. }
  117.  
  118.     /* DoBeep():
  119.      *
  120.      *    The real interface to the beep routine.
  121.      */
  122.  
  123. BOOL
  124. DoBeep()
  125. {
  126.     BellSignal();
  127.  
  128.     return(FALSE);
  129. }
  130.  
  131.     /* DoLF():
  132.      *
  133.      *    Special function: perform line feed.
  134.      */
  135.  
  136. BOOL
  137. DoLF()
  138. {
  139.         /* This takes care of regular jump scrolling */
  140.  
  141.     if(CursorY == Bottom && Bottom > 0 && Config->EmulationConfig->MaxJump > 1)
  142.     {
  143.         LONG Scroll,TotalLines,OldBack = BackgroundPen;
  144.  
  145.         Scroll = Config->EmulationConfig->MaxJump;
  146.  
  147.             /* How tall is the current scroll region? */
  148.  
  149.         TotalLines = Bottom - Top + 1;
  150.  
  151.             /* Don't scroll more than the entire screenful */
  152.  
  153.         if(Scroll > TotalLines)
  154.             Scroll = TotalLines;
  155.  
  156.         if(OldBack)
  157.         {
  158.             BackgroundPen = 0;
  159.  
  160.             UpdatePens();
  161.         }
  162.  
  163.             /* Scroll the region... */
  164.  
  165.         ScrollRegion(Scroll);
  166.  
  167.             /* Reposition the cursor */
  168.  
  169.         if(CursorY > Scroll)
  170.             CursorY -= Scroll;
  171.         else
  172.             CursorY = 0;
  173.  
  174.         if(OldBack)
  175.         {
  176.             BackgroundPen = OldBack;
  177.  
  178.             UpdatePens();
  179.         }
  180.     }
  181.  
  182.     DownLine();
  183.  
  184.     RepositionCursor();
  185.  
  186.     return(FALSE);
  187. }
  188.  
  189.     /* DoShiftIn():
  190.      *
  191.      *    Special function: Shift into graphics mode
  192.      */
  193.  
  194. BOOL
  195. DoShiftIn()
  196. {
  197.     if(CharMode[1] == TABLE_GFX && GFX)
  198.         CurrentFont = GFX;
  199.  
  200.     if(CharMode[1] == TABLE_ASCII)
  201.         CurrentFont = TextFont;
  202.  
  203.     SetFont(RPort,CurrentFont);
  204.  
  205.     ConOutputUpdate();
  206.  
  207.     Charset = 1;
  208.  
  209.     return(FALSE);
  210. }
  211.  
  212.     /* DoShiftOut():
  213.      *
  214.      *    Special function: Shift out of graphics mode
  215.      */
  216.  
  217. BOOL
  218. DoShiftOut()
  219. {
  220.     if(CharMode[0] == TABLE_GFX && GFX)
  221.         CurrentFont = GFX;
  222.  
  223.     if(CharMode[0] == TABLE_ASCII)
  224.         CurrentFont = TextFont;
  225.  
  226.     SetFont(RPort,CurrentFont);
  227.  
  228.     ConOutputUpdate();
  229.  
  230.     Charset = 0;
  231.  
  232.     return(FALSE);
  233. }
  234.  
  235.     /* DoCR_LF():
  236.      *
  237.      *    Special function: perform carriage return and line feed.
  238.      */
  239.  
  240. BOOL
  241. DoCR_LF()
  242. {
  243.     CursorX = 0;
  244.  
  245.     DownLine();
  246.  
  247.     RepositionCursor();
  248.  
  249.     return(FALSE);
  250. }
  251.  
  252.     /* DoFF():
  253.      *
  254.      *    Special function: perform form feed.
  255.      */
  256.  
  257. BOOL
  258. DoFF()
  259. {
  260.     if(Config->EmulationConfig->NewLineMode)
  261.     {
  262.         CursorX = 0;
  263.  
  264.         DoCR_LF();
  265.     }
  266.     else
  267.     {
  268.         EraseScreen("2");
  269.  
  270.         CursorX = CursorY = 0;
  271.  
  272.         RepositionCursor();
  273.  
  274.         ConFontScaleUpdate();
  275.     }
  276.  
  277.     return(FALSE);
  278. }
  279.  
  280.     /* DoLF_FF_VT():
  281.      *
  282.      *    Special function: handle line feed, form feed and vertical
  283.      *    tab.
  284.      */
  285.  
  286. BOOL
  287. DoLF_FF_VT()
  288. {
  289.     if(Config->EmulationConfig->NewLineMode)
  290.         DoCR_LF();
  291.     else
  292.         DoLF();
  293.  
  294.     return(FALSE);
  295. }
  296.  
  297.     /* DoCR():
  298.      *
  299.      *    Special function: handle carriage return.
  300.      */
  301.  
  302. BOOL
  303. DoCR()
  304. {
  305.     if(Config->EmulationConfig->NewLineMode)
  306.         DoCR_LF();
  307.     else
  308.     {
  309.         CursorX = 0;
  310.  
  311.         RepositionCursor();
  312.     }
  313.  
  314.     return(FALSE);
  315. }
  316.  
  317.     /* DoTab():
  318.      *
  319.      *    Special function: handle tab, move cursor to next
  320.      *    tab stop.
  321.      */
  322.  
  323. BOOL
  324. DoTab()
  325. {
  326.     LONG Column;
  327.  
  328.     if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
  329.         Column = LastColumn;
  330.     else
  331.         Column = ((LastColumn + 1) / 2) - 1;
  332.  
  333.     if(Config->EmulationConfig->LineWrap)
  334.     {
  335.         if(CursorX >= LastColumn)
  336.         {
  337.             CursorX = 0;
  338.  
  339.             DownLine();
  340.         }
  341.         else
  342.         {
  343.             while(CursorX < Column)
  344.             {
  345.                 CursorX++;
  346.  
  347.                 if(TabStops[CursorX])
  348.                     break;
  349.             }
  350.         }
  351.     }
  352.     else
  353.     {
  354.         while(CursorX < Column)
  355.         {
  356.             CursorX++;
  357.  
  358.             if(TabStops[CursorX])
  359.                 break;
  360.         }
  361.     }
  362.  
  363.     RepositionCursor();
  364.  
  365.     return(FALSE);
  366. }
  367.  
  368.     /* DoEnq():
  369.      *
  370.      *    Special function: send answerback message.
  371.      */
  372.  
  373. BOOL
  374. DoEnq()
  375. {
  376.     if(Config->EmulationConfig->AnswerBack[0])
  377.         SerialCommand(Config->EmulationConfig->AnswerBack);
  378.  
  379.     return(FALSE);
  380. }
  381.  
  382.     /* DoEsc():
  383.      *
  384.      *    Start new control sequence.
  385.      */
  386.  
  387. BOOL
  388. DoEsc()
  389. {
  390.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  391.         (* ConDump)("^",1);
  392.  
  393.     return(TRUE);
  394. }
  395.  
  396.     /* DoCsi():
  397.      *
  398.      *    Start new control sequence.
  399.      */
  400.  
  401. BOOL
  402. DoCsi()
  403. {
  404.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  405.         (* ConDump)("^[",2);
  406.  
  407.     return(ParseCode('['));
  408. }
  409.  
  410.     /* DoNewEsc(LONG Char):
  411.      *
  412.      *    Start new control sequence.
  413.      */
  414.  
  415. BOOL
  416. DoNewEsc(LONG UnusedChar)
  417. {
  418.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  419.         (* ConDump)("^",1);
  420.  
  421.     DoCancel();
  422.  
  423.     return(TRUE);
  424. }
  425.  
  426.     /* DoNewCsi(LONG Char):
  427.      *
  428.      *    Start new control sequence.
  429.      */
  430.  
  431. BOOL
  432. DoNewCsi(LONG UnusedChar)
  433. {
  434.     if(Config->TerminalConfig->EmulationMode == EMULATION_TTY)
  435.         (* ConDump)("^[",2);
  436.  
  437.     DoCancel();
  438.  
  439.     return(ParseCode('['));
  440. }
  441.